package com.hd.service.generator.impl;

import java.util.List;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.hd.dao.BaseDao;
import com.hd.entity.generator.CodeBeanProperty;
import com.hd.service.generator.CodeBeanPropertyService;

@Service("codeBeanPropertyService")
public class CodeBeanPropertyServiceImpl implements CodeBeanPropertyService {
    @Autowired
    private BaseDao<CodeBeanProperty,String>codeBeanPropertyDao;
    @Override
    public void save(CodeBeanProperty codeBeanProperty) {
    	codeBeanProperty.setId(UUID.randomUUID().toString());
        codeBeanPropertyDao.save(codeBeanProperty);
    }
    // 查询最大主键
   	private String geNextPrimaryKey() {
   		Object maxValue = codeBeanPropertyDao.getMaxValue(CodeBeanProperty.class, "id");
   		if (maxValue != null) {
   			Long value = Long.valueOf((String) maxValue) + 1L;
   			return value.toString();
   		}
   		return "1";
   	}
    @Override
    public void delete(String tableName) {
        String hql="delete from  CodeBeanProperty where tableName=?";
        codeBeanPropertyDao.execute(hql,tableName);
    }

    @Override
    public List<CodeBeanProperty> findByTableName(String tableName) {
        String hql="from CodeBeanProperty where tableName=?";
        return codeBeanPropertyDao.find(hql,tableName);
    }
}
